bitkeeper revision 1.1159.194.1 (41a5c5c5J8BRAOOMMsDGqEcd_8brmg)
authorkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 25 Nov 2004 11:45:09 +0000 (11:45 +0000)
committerkaf24@scramble.cl.cam.ac.uk <kaf24@scramble.cl.cam.ac.uk>
Thu, 25 Nov 2004 11:45:09 +0000 (11:45 +0000)
Sort exception tables during Xen boot. This will fix some nasty crashes
that some people have seen in the last day or so.

xen/arch/x86/extable.c
xen/arch/x86/setup.c
xen/include/asm-x86/x86_32/uaccess.h

index 54251cc3c51451bf7956afb9bff3b35329694b22..d3292027e0ffb391b367c2b6638fb6ef6d93c202 100644 (file)
@@ -3,6 +3,36 @@
 #include <xen/spinlock.h>
 #include <asm/uaccess.h>
 
+extern struct exception_table_entry __start___ex_table[];
+extern struct exception_table_entry __stop___ex_table[];
+extern struct exception_table_entry __start___pre_ex_table[];
+extern struct exception_table_entry __stop___pre_ex_table[];
+
+static void sort_exception_table(struct exception_table_entry *start,
+                                 struct exception_table_entry *end)
+{
+    struct exception_table_entry *p, *q, tmp;
+
+    for ( p = start; p < end; p++ )
+    {
+        for ( q = p-1; q > start; q-- )
+            if ( p->insn > q->insn )
+                break;
+        if ( ++q != p )
+        {
+            tmp = *p;
+            memmove(q+1, q, (p-q)*sizeof(*p));
+            *q = tmp;
+        }
+    }
+}
+
+void sort_exception_tables(void)
+{
+    sort_exception_table(__start___ex_table, __stop___ex_table);
+    sort_exception_table(__start___pre_ex_table, __stop___pre_ex_table);
+}
+
 static inline unsigned long
 search_one_table(const struct exception_table_entry *first,
                 const struct exception_table_entry *last,
@@ -28,21 +58,15 @@ search_one_table(const struct exception_table_entry *first,
 unsigned long
 search_exception_table(unsigned long addr)
 {
-    extern const struct exception_table_entry __start___ex_table[];
-    extern const struct exception_table_entry __stop___ex_table[];
     return search_one_table(
         __start___ex_table, __stop___ex_table-1, addr);
 }
 
-#ifdef __i386__
 unsigned long
 search_pre_exception_table(unsigned long addr)
 {
-    extern const struct exception_table_entry __start___pre_ex_table[];
-    extern const struct exception_table_entry __stop___pre_ex_table[];
     unsigned long fixup = search_one_table(
         __start___pre_ex_table, __stop___pre_ex_table-1, addr);
     DPRINTK("Pre-exception: %08lx -> %08lx\n", addr, fixup);
     return fixup;
 }
-#endif
index 7ed4bf0744b72f7c3831e52d5363ff1422a9d2d0..cf6f7980e15621aad151afa8c2b838a3a1cffd95 100644 (file)
@@ -326,6 +326,8 @@ void __init start_of_day(void)
     if ( opt_watchdog ) 
         nmi_watchdog = NMI_LOCAL_APIC;
 
+    sort_exception_tables();
+
     /* Tell the PCI layer not to allocate too close to the RAM area.. */
     low_mem_size = ((max_page << PAGE_SHIFT) + 0xfffff) & ~0xfffff;
     if ( low_mem_size > pci_mem_start ) pci_mem_start = low_mem_size;
index 1b1b28bfe5c6b5522b8ef61dc44e51687c5f4716..7531a294454d396c496c6c77d0cc91b6cb9bf11a 100644 (file)
@@ -85,6 +85,7 @@ struct exception_table_entry
 };
 
 extern unsigned long search_exception_table(unsigned long);
+extern void sort_exception_tables(void);
 
 /**
  * get_user: - Get a simple variable from user space.